package com.bosch.in.rtp1.ept.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.bosch.in.rtp1.ept.dao.AuthenticationDao;
import com.bosch.in.rtp1.ept.util.SQLStatementLoader;

/**
 * Concrete JDBC implementation of AuthenticationDao.
 * @author TPR1HC
 *
 */
public class AuthenticationJDBCDao extends GenericDao implements AuthenticationDao {
	
	private static final Logger LOGGER = Logger.getLogger(AuthenticationJDBCDao.class);
	
	/**
	 * Constructor to inject connection
	 * @param con	DB connection
	 */
	public AuthenticationJDBCDao(Connection con) {
		super(con);
	}

	@Override
	public boolean validatePassword(String password) throws SQLException {
		LOGGER.debug("Begin validatePassword");
		boolean found = false;
		
		//load query statement
		String queryString = SQLStatementLoader.getPasswordQuery();
		
		//execute query
		ResultSet resultSet = executeQuery(queryString, new String[] {password});
		
		//examine result set
		if (resultSet.next()) {
			found = true;
		}
		// close statement, result set
		resultSet.close();
		close();
		LOGGER.debug("End validatePassword");
		
		return found;
	}
	
	
}
